<?php

use App\Models\AssetCategory;
use App\Models\AssetStatus;
use Illuminate\Database\Seeder;

class AssetSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {

        $this->initStatuses();
        $this->initCategories();
    }

    private function initStatuses(): void
    {
        $data = [
            ["name" => "可用", "label" => "可用"],
            ["name" => "借出", "label" => "借出"],
            ["name" => "遗失", "label" => "遗失"],
            ["name" => "维修中", "label" => "维修中"]
        ];
        collect($data)->each(function ($raw) {
            $status = new AssetStatus($raw);
            $status->save();
        });
    }

    private function initCategories()
    {
        $originalCategories = [
            ["相机", "电影摄影机", "相机", "运动相机"],
            ["镜头", "定焦", "变焦"],
            ["摄影附件", "监视器", "EVF", "录机", "转接环", "摄影机模块", "无线图传", "时码器", "镜头控制", "遮光/滤镜系统"],
            ["套件", "手柄", "滑条", "笼子", "底座", "导管", "电池扣板"],
            ["Grip", "通用支架", "转换头", "多孔板", "夹具", "吸盘", "通用管材", "绳索", "配重"],
            ["存储媒介", "SATA SSD", "SD", "一体硬盘", "3.5寸机械硬盘", "2.5寸机械硬盘", "硬盘阵列"],
            ["电源", "电池", "移动电源", "充电器", "适配器"],
            ["灯光", "管灯", "板灯", "筒灯", "菲涅尔灯", "灯泡", "控光附件", "电子控制附件"],
            ["支撑/移动", "脚架系统", "电子云台", "轨道/飞猫系统", "摇臂", "飞行器", "平衡车", "FPV头盔", "灯架", "机械臂"],
            ["麦克风", "机头麦", "枪麦", "大振膜", "领夹麦", "无线音频传输"],
            ["录音机/调音台", "调音台", "录音机"],
            ["声音附件", "监听耳机", "挑杆", "麦克风防风罩"],
            ["网络硬件", "路由器", "交换机", "AP"],
            ["信号处理和分发", "LUTBox", "转换器", "切换/复制器"],
            ["计算机外设", "读卡器、读盘器", "拓展坞", "采集卡", "上屏卡", "调色台", "通用外设"],
            ["计算机", "工作站", "服务器", "移动平台"],
            ["现场沟通", "无线通话系统", "对讲机", "激光笔"],
            ["线缆", "信号线", "DC电源线", "AC电源线", "连接器", "USB线"],
            ["箱包车", "箱子", "内胆", "软包", "小车", "苹果箱", "马鞍袋"],
            ["测量仪器", "测试卡", "照度/亮度/色度计", "测距工具", "屏幕色度计", "分贝计", "电子秤", "万用表"],
            ["五金工具", "螺丝刀/扳手", "锤子", "钳/剪", "电动工具", "气动工具", "热力工具"],
            ["耗材", "胶带耗材包", "色纸耗材包", "清洁用品耗材包"]
        ];
        $data = collect($originalCategories);
        DB::beginTransaction();
        $convertedData = $data->map(function($category, $key){
            $c = collect($category);
            $primaryCategoryName = $c->first();
            $subCategories = $c->slice(1);
            $primaryCategory = AssetCategory::create([
                "name" => $primaryCategoryName
            ]);
            $pId = $primaryCategory->id;
            $subCategories->each(function($subCategoryName, $key) use($pId){
                AssetCategory::create([
                    "name" => $subCategoryName,
                    "parent_id" => $pId
                ]);
            });
            // create main category
            // create each sub category for main category
        });
        DB::commit();
    }
}
